﻿#include <stdio.h>
#define MONTHS 12
#define YEARS  5
void total_rain(const float arr[][MONTHS], int m);
void average_rain(const float arr[][MONTHS], int m);
int main(void)
{
	const float rain[YEARS][MONTHS] = {
		4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6,
		8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3,
		9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4,
		7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2,
		7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2 };
	total_rain(rain, YEARS);
	average_rain(rain, YEARS);
	return 0;
}
void total_rain(const float arr[][MONTHS], int m)
{
	int i, j;
	double subtot, total = 0;
	printf("YEAR		RAINFALL(inches)\n");
	for (i = 0; i < m; i++)
	{
		for (subtot = 0, j = 0; j < MONTHS; j++)
			subtot += arr[i][j];
		printf("%d		%3g\n", 2010 + i, subtot);
		total += subtot;
	}
	printf("The yearly average is %3g inches.\n", total / YEARS);
}
void average_rain(const float arr[][MONTHS], int m)
{
	int i, j;
	double total;
	printf("MONTHLY AVERAGES:\n");
	printf("Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec\n");
	for (i = 0; i < MONTHS; i++)
	{
		for (total = 0, j = 0; j < m; j++)
			total += arr[j][i];
		printf("%.1f  ", total / m);
	}
	printf("\n");
}
